package com.tchintech.pay.view.activity;

import android.content.Intent;
import android.view.KeyEvent;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;

import com.tchintech.pay.delegate.BankWebviewDelegate;
import com.tchintech.pay.frame.presenter.ActivityPresenter;

/**
 * Created by Administrator on 2017/7/10 0010.
 */

public class BankWebview extends ActivityPresenter<BankWebviewDelegate> {
    private Intent intent;
    private String url;
    private WebView webviwe;

    @Override
    protected Class<BankWebviewDelegate> getDelegateClass() {
        return BankWebviewDelegate.class;
    }

    @Override
    protected void initView() {
        super.initView();


    }

    @Override
    protected void initData() {
        super.initData();
        webviwe= viewDelegate.getWeb();
        url = getIntent().getStringExtra("url");
        webviwe.loadUrl(url);
        WebSettings webSettings = webviwe.getSettings();
        //使用js展示js网页特效
        webSettings.setJavaScriptEnabled(true);
        //webviwe.setWebViewClient(new MyWebViewClient());
        //webView实现内部跳转不需要调用外部浏览器
        webviwe.setWebViewClient(new WebViewClient(){
            @Override
            public boolean shouldOverrideUrlLoading(WebView view, String url) {
                view.loadUrl(url);
                return true;
            }
        });
    }

    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if ((keyCode == KeyEvent.KEYCODE_BACK) && webviwe.canGoBack()) {
            // 返回键退回
            webviwe.goBack();
            return true;
        }
        return super.onKeyDown(keyCode, event);
    }
}
